import 'package:flutter/material.dart';
import 'package:zootix/screens/follow_conversation/zt_followed.dart';
import 'package:zootix/screens/follow_conversation/zt_conversation.dart';
import 'package:zootix/util/zt_screen_adaper_util.dart';
import 'package:zootix/widgets/zt_want_keep_alive.dart';

class ZtFollowConversationContainerPage extends StatefulWidget {
  const ZtFollowConversationContainerPage({super.key});

  @override
  State<ZtFollowConversationContainerPage> createState() =>
      _ZtFollowConversationContainerPageState();
}

class _ZtFollowConversationContainerPageState
    extends State<ZtFollowConversationContainerPage> {
  @override
  Widget build(BuildContext context) {
    return DefaultTabController(
      length: 2,
      child: Scaffold(appBar: _buildAppBar(), body: _buildBody()),
    );
  }

  PreferredSizeWidget _buildAppBar() {
    return PreferredSize(
        preferredSize: Size.fromHeight(80), // 自定义AppBar的高度
        child: AppBar(
          flexibleSpace: Container(
            decoration: const BoxDecoration(
              image: DecorationImage(
                image: AssetImage('assets/images/messages_header_bg.png'),
                fit: BoxFit.cover,
              ),
            ),
          ),
          bottom: _buildTabBar(),
        ));
  }

  PreferredSizeWidget _buildTabBar() {
    final tabs = [
      const Tab(
        child: Text(
          "Messages",
        ),
      ),
      const Tab(
        child: Text(
          "Followed",
        ),
      ),
    ];

    return TabBar(
      padding: EdgeInsets.fromLTRB(0, 0, ZtScreenAdaper.screenWidth() / 3, 0),
      tabs: tabs,
      labelStyle: TextStyle(
          fontSize: ZtScreenAdaper.sp(20), fontWeight: FontWeight.w400),
      unselectedLabelStyle: TextStyle(fontSize: ZtScreenAdaper.sp(18)),
      indicator: UnderlineTabIndicator(
        borderSide: BorderSide(
          width: ZtScreenAdaper.height(6), // 指示器横线宽度
          color: const Color.fromRGBO(171, 238, 28, 1), // 指示器横线颜色
        ),
        borderRadius: const BorderRadius.all(Radius.circular(10)),
        insets: EdgeInsets.fromLTRB(ZtScreenAdaper.width(5), 0,
            ZtScreenAdaper.width(5), ZtScreenAdaper.height(14)), // 指示器横线底部偏移量
      ),
      indicatorSize: TabBarIndicatorSize.label,
    );
  }

  Widget _buildBody() {
    return Column(children: [
      Expanded(
          child: TabBarView(
        physics: const AlwaysScrollableScrollPhysics(),
        children: [
          ZtWantKeepAlive(child: ZtConversationList()),
          ZtWantKeepAlive(child: ZtFollowedList()),
        ],
      )),
    ]);
  }
}
